#pragma once
#include <iostream>
#include <unistd.h>
#include <fcntl.h>

#include "Log.hpp"
// 用来设置文件描述符为非阻塞

void SetNonBlock(int sockfd)
{
    int fl = fcntl(sockfd, F_GETFL);
    if (fl < 0)
    {
        lg.LogMessage(Info, "get a sockfd error");
        exit(-1);
    }

    int n = fcntl(sockfd, F_SETFL, fl | O_NONBLOCK);

    lg.LogMessage(Info, "set a sofd nonblock %d", sockfd);
}